package com.bianmaba.dc.bean;

public enum TaskStatus {
    UNKNOWN("未知", -1),
    WAIT("待执行", 1),
    RUNNING("执行中", 2),
    SUCCESSFUL("已完成", 3),

    UNSUCCESSFUL("失败", 4),
    EXCEPTIONAL("异常", 5),
    SYSTEM_TERMINATED("系统终止", 6),
    USER_TERMINATED("用户终止", 7);

    // 成员变量
    private String name;
    private int index;

    // 构造方法
    TaskStatus(String name, int index) {
        this.name = name;
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return index;
    }

    // 普通方法
    public static String getName(int index) {
        for (TaskStatus result : values()) {
            if (result.getIndex() == index) {
                return result.getName();
            }
        }
        return null;
    }

    public static Integer getIndex(String name) {
        for (TaskStatus item : values()) {
            if (item.getName().equals(name)) {
                return item.getIndex();
            }
        }
        return -1;
    }

    public static TaskStatus get(int index) {
        for (TaskStatus item : values()) {
            if (item.getIndex() == index) {
                return item;
            }
        }
        return UNKNOWN;
    }

    public static TaskStatus get(String name) {
        for (TaskStatus item : values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return UNKNOWN;
    }
}
